#include<bits/stdc++.h>
using namespace std;
int T,n,a[200009],cnt[1000009],ans;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>T;
    while(T--)
    {
        memset(cnt,0,sizeof(cnt));
        ans=0;
        cin>>n;
        for(int i=1;i<=n;++i)
        {
            cin>>a[i];
            ++cnt[a[i]];
        }
        for(int i=1;i<=n;++i)
        {
            ans+=a[i]*(cnt[i]-1);
            cnt[i]=1;
        }
        cout<<ans<<'\n';
    }
    return 0;
}